<?php

namespace app\data\controller\user;

use app\data\model\DataUser;
use app\data\model\ShopOrder;
use app\data\service\UserAdminService;
use app\data\service\OrderService;
use think\admin\Controller;

/**
 * 会员订单
 * Class Message
 * @package app\data\controller\user
 */
class Vip extends Controller
{
    /**
     * 会员订单列表
     * @auth true
     * @menu true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        $this->title = '会员订单管理';
        // 订单列表查询
        $query = ShopOrder::mQuery();
        $query->equal('status')->dateBetween('create_at,payment_datetime');
        // 用户搜索查询
        $db = DataUser::mQuery()->where(['payment_type'=>2])->like('phone|username|nickname#name')->db();
        if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
         // 分页排序处理
        $lists  = $query->order('id desc')->page(true,false,false);
        if(empty($lists['list']) === FALSE){
            foreach ($lists['list'] as &$lv){
                $lv['payment_amount'] = sprintf("%.2f",$lv['payment_amount']/100);
            }
        }
        $this->list = $lists['list'];
        $this->fetch();
    }

    /**
     * 订单列表处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _index_page_filter(array &$data)
    {
        UserAdminService::buildByUid($data);
        OrderService::buildData($data);
    }
}
